import { Form, redirect, useFetcher } from "react-router";
import { DeleteLocation } from "~/lib/server";
import type { Route } from "./+types/delete";
import { ActionButton, DialogTrigger,AlertDialog } from "@adobe/react-spectrum";


export async function clientAction({ params }: Route.ActionArgs) {

    await DeleteLocation(params.locationId);
    return redirect("/locations/0");
}


export function DestroyLocation({ location }: { location: Pick<Location, "id"> }) {


     let onPrimaryAction = () =>{
    DeleteLocation(location.id);
    return redirect("/locations/0");
         
    }
    return (
        

            
            
            <DialogTrigger>
  <ActionButton>删除</ActionButton>
  <AlertDialog
    variant="destructive"
    title={`删除 ${location.name}`}
    primaryActionLabel="确认"
    cancelLabel="取消"
     onPrimaryAction={onPrimaryAction}>
    确认删除？
  </AlertDialog>
</DialogTrigger>


    );
}

